package com.hubujun.driverlicense;

import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;

import com.hubujun.driverlicense.util.Ln;


/**
 * 应用程序上下文
 * 
 *
 */
public class ApplicationContext {

	private static Context context;

	private static String packageName = "com.hubujun.driverlicense";

	public static void init(Context con) {
		context = con;
		packageName = con.getPackageName();
		Ln.i("setup application context for package: %s", packageName);
	}

	public static Context getContext() {
		return context;
	}

	public static String getPackageName() {
		return packageName;
	}

	public static String getPreferencesName() {
		return packageName + "_preferences";
	}

	public static SharedPreferences getSharedPreferences(int mode) {
		return context.getSharedPreferences(getPreferencesName(), mode);
	}

	public static String getCurProcessName() {
		int pid = android.os.Process.myPid();
		ActivityManager mActivityManager = (ActivityManager) ApplicationContext.getContext().getSystemService(Context.ACTIVITY_SERVICE);
		for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
			if (appProcess.pid == pid) {
				return appProcess.processName;
			}
		}
		return null;
	}
}
